//
//  DestFirstCellInfoViewController.m
//  TravelEveryDay
//
//  Created by dlios on 15/10/19.
//  Copyright © 2015年 com.lanou3g. All rights reserved.
//

#import "DestFirstCellInfoViewController.h"
#import "BaseHeader.h"
@interface DestFirstCellInfoViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UIView *destTabbleViewHeaderView;
@property (nonatomic,strong)UITableView * destTabelView;
@property(nonatomic,strong)UIImageView *destHostImageView;
@property(nonatomic,strong)NSString *HeaderImageViewString;//头部图片的网址
@property(nonatomic,strong)UIImageView *destPhtotoesImageView;
@property(nonatomic,strong)UILabel *photoCountLabel;
@property(nonatomic,strong)NSNumber *photoCountString;//图片个数
@end

@implementation DestFirstCellInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBarHidden = YES;
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self createTableView];
   // [self crecteTabelViewHeader];
    [self createBackButton];
    [self getDestData];
}
#pragma mark - 创建tableView
- (void)createTableView {
    _destTabelView = [[UITableView  alloc]initWithFrame:self.view.frame];
    [self.view addSubview:_destTabelView];
}
#pragma mark  - 创建头部
- (void)crecteTabelViewHeader {
    _destTabbleViewHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 400 *HEIGHT)];
    _destHostImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 280 *HEIGHT)];
    NSURL *url = [NSURL URLWithString:_HeaderImageViewString];
    [_destHostImageView sd_setImageWithURL:url placeholderImage:PLACEHOLDERIMAGE];
    
    _destPhtotoesImageView = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 80*WIDTH, 250 *HEIGHT, 20*WIDTH, 20*HEIGHT)];
    _destPhtotoesImageView.image  =[UIImage imageNamed:@"Desticonfont-photo.png"];
    _photoCountLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 58*WIDTH , 250 *HEIGHT, 75 *WIDTH, 20 * WIDTH)];
    _photoCountLabel.textAlignment = NSTextAlignmentLeft;
    _photoCountLabel.textColor = [UIColor whiteColor];
    _photoCountLabel.text = [NSString stringWithFormat:@"%@",_photoCountString];
    [self.view addSubview:_photoCountLabel];
    [_destHostImageView addSubview:_destPhtotoesImageView];
    [_destTabbleViewHeaderView addSubview:_destHostImageView];
    _destTabelView.tableHeaderView = _destTabbleViewHeaderView;
    
}
#pragma mark -  创建返回按钮
- (void)createBackButton {
    UIButton *backButton =[UIButton buttonWithType:UIButtonTypeCustom];
    [backButton setImage:[UIImage imageNamed:@"play-jiantouzuo.png"] forState:UIControlStateNormal];
    backButton.frame =CGRectMake(5, 20, 30, 30);
    [backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backButton];
}

- (void)getDestData {
    [DestAFNDataBlock string:[NSString stringWithFormat:@"http://api.breadtrip.com/destination/place/%@/%@/",_type,_MyId] AFNData:^(id block) {
        NSLog(@"===33==%@",block);
        //首先给最顶上的图片赋值
        NSMutableArray *hottest_placesArray = [block objectForKey:@"hottest_places"];
        _HeaderImageViewString = [[hottest_placesArray objectAtIndex:0]objectForKey:@"photo"];
        _photoCountString = [block objectForKey:@"photo_count"];
        [self crecteTabelViewHeader];
        [_destTabelView reloadData];
    } AFNData1:^(id block) {
        
        
    }];
}

#pragma mark - 返回上一页面的方法
- (void)back {
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
